#ifndef PROCESSCTRL_H
#define PROCESSCTRL_H
#include <windows.h>
#include <string>
#include <vector>
#include <stdexcept>
#include "../_singleton.h"

class ProcessCtrl: public _Singleton<ProcessCtrl> {
public:
    bool StartProcess(
        const std::wstring& exePath,
        const std::vector<std::wstring>& args = {},
        const std::wstring& workingDir = L"");
    bool IsRunning() const;
    bool Terminate(unsigned exitCode = 0);
    bool WaitForExit(DWORD timeoutMs = INFINITE);
    ~ProcessCtrl() { Cleanup(); }
private:
    friend class _Singleton<ProcessCtrl>;

    ProcessCtrl();
    void Cleanup();


    PROCESS_INFORMATION m_processInfo = {0};
    bool m_bStarted = false;
};
#endif // PROCESSCTRL_H
